package gamelogic;

import java.util.Arrays;


public class Word {
	char[] wordChars;
	char[] mixedWordChars;
	String word;

	Word(int NumberOfLetters) {
		// get word from database
		// wordchars = ...

		exchangePlacesOfLetters();
	}
	/**
	 * This method exchange places of letters. The result saved in mixedWordChars.
	 */
	private void exchangePlacesOfLetters() {
		int numberOfLetters = wordChars.length;
		int[] randomIndexes = new int[numberOfLetters];
		for (int i = 0; i < numberOfLetters; i++) {
			randomIndexes[i] = i;
		}
		mixedWordChars = new char[numberOfLetters];
		while (true) {
			for (int i = 0; i < numberOfLetters; i++) {
				int r = (int) (Math.random() * (i + 1)); // int between 0 and i
				int swap = randomIndexes[r];
				randomIndexes[r] = randomIndexes[i];
				randomIndexes[i] = swap;
			}
			for (int i = 0; i < numberOfLetters; i++) {
				mixedWordChars[randomIndexes[i]] = wordChars[i];
			}

			if (Arrays.equals(wordChars,mixedWordChars)) {
				continue;
			}
			break;
		}

	}


}
